package com.dev.toolkit.common.enums;

import lombok.Getter;

/**
 * @author ZhuYouBin
 * @version 1.0.0
 * @date 2024/4/15 22:17
 * @description 数据库类型和Java数据类型映射枚举
 */
@Getter
public enum TypeConversionEnum {
    VARCHAR("VARCHAR", "String"),
    CHAR("CHAR", "String"),
    TEXT("TEXT", "String"),
    TINYTEXT("TINYTEXT", "String"),
    MEDIUMTEXT("MEDIUMTEXT", "String"),
    LONGTEXT("LONGTEXT", "String"),
    DATE("DATE", "Date"),
    YEAR("YEAR", "Date"),
    TIMESTAMP("TIMESTAMP", "Date"),
    TIME("TIME", "Time"),
    DATETIME("DATETIME", "Date"),
    INT("INT", "Integer"),
    TINYINT("TINYINT", "Integer"),
    MEDIUMINT("MEDIUMINT", "Integer"),
    SMALLINT("SMALLINT", "Integer"),
    BIT("BIT", "Integer"),
    BIGINT("BIGINT", "Long"),
    DOUBLE("DOUBLE", "Double"),
    FLOAT("FLOAT", "Double"),
    DECIMAL("DECIMAL", "BigDecimal"),
    TINYBLOB("TINYBLOB", "byte[]"),
    BLOB("BLOB", "byte[]"),
    MEDIUMBLOB("MEDIUMBLOB", "byte[]"),
    LONGBLOB("LONGBLOB", "byte[]");

    private final String code;
    private final String value;

    TypeConversionEnum(String code, String value) {
        this.code = code;
        this.value = value;
    }

    public static String getValueByCode(String code) {
        for (TypeConversionEnum typeConversionEnum : TypeConversionEnum.values()) {
            if (typeConversionEnum.getCode().equals(code)) {
                return typeConversionEnum.getValue();
            }
        }
        return null;
    }
}